package com.m3958.firstgwt.client.jso;

import com.google.gwt.core.client.JsArray;


public class ArticleJso extends BaseModelJso {
	  // Overlay types always have protected, zero-arg ctors
	  protected ArticleJso() { }
	  
	  public final native String getTitle()/*-{return this.title;}-*/;
	  public final native String getExcerpt()/*-{return this.excerpt;}-*/;
	  public final native String getContent()/*-{return this.content;}-*/;
	  public final native String getFlag()/*-{return this.flag;}-*/;
	  public final native AssetJso getTitleImg()/*-{return this.titleImg;}-*/;
	  public final native JsArray<AssetJso> getContentImgs()/*-{return this.contentImgs;}-*/;
	  public final native JsArray<AssetJso> getAttachments()/*-{return this.attachments;}-*/;
	  
	  public final native JsArray<AssetJso> getAttachmentsList()/*-{
		  	var aja = [];
		  	var add2aja = function(asset,atype){
		  		var find = false;
		  		for(var i=0;i<aja.length;i++){
		  			var ca = aja[i];
		  			if(ca.id == asset.id){//找到了
		  				if(atype == 'titleImg'){
		  					ca.isTitleImg = true;
		  				}else if(atype == 'contentImg'){
		  					ca.isContentImg = true;
		  				}else if(atype == 'attachment'){
		  					ca.isAttachment = true;
		  				}
		  				find = true;
		  				break;
		  			}
		  		}
		  		if(!find){
	  				if(atype == 'titleImg'){
	  					asset.isTitleImg = true;
	  				}else if(atype == 'contentImg'){
	  					asset.isContentImg = true;
	  				}else if(atype == 'attachment'){
	  					asset.isAttachment = true;
	  				}
	  				aja.push(asset);
		  		}
		  	};
		  	if(this.titleImg){
		  		add2aja(this.titleImg,'titleImg');
		  	}
		  	var i;
		  	for(i=0;i<this.contentImgs.length;i++){
		  		add2aja(this.contentImgs[i],'contentImg');
		  	}
		  	for(i=0;i<this.attachments.length;i++){
		  		add2aja(this.attachments[i],'attachment');
		  	}
	  		return aja;
	  }-*/;
}
